home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / INFO / DOSTIPS1.ZIP / DESIGN.TXT < prev    next >
Text File  |  1985-11-24  |  20KB  |  493 lines

  1.                            Designer Screens
  2.   (PC World November 1985 by B. Alperson, A. Fluegelman, & L. Magid)
  3.  
  4.      Control over the video display constitutes far more than window
  5. dressing: The screen is the medium for supplying information to the
  6. user.  A well-designed screen enhances not only the aesthestics but
  7. also the efficiency of program execution and information presentation.
  8. It helps locate the apporpriate instructions and interpret program
  9. output.  It can put the final polish on a system.
  10.  
  11.      With DOS 2.0's display capabilities and screen control features,
  12. you can use graphics characters, redesign the DOS prompt, and control
  13. parameters such a inverse video, cursor location, foreground and
  14. background colors, screen width, and screen mode.
  15.  
  16.      Some people go to the trouble of writing elaborate menu programs
  17. in BASIC or another language.  There is a simpler approach.  The
  18. extended ASCII character set can help create custom menus.  It includes
  19. solid lines (ASCII 179, 180, 193, 194, 195, 196 and 197), single-line
  20. corners (ASCII 191, 192, 217 and 218), double lines (ASCII 185, 186,
  21. 202, 230, 204, 205 and 206), double-line corners (ASCII 187, 188, 200
  22. and 201), and special graphics symbols such as the large dot (ASCII
  23. 249) and the right arrowhead (ASCII 16).
  24.  
  25.      If you hold down the Alt key while you type the desired ASCII
  26. number on the numeric keypad, you'll discover that you can access all
  27. the symbols above ASCII 127.  The corresponding character appears as
  28. soon as you release the Alt key.  If you are using a keyboard macro
  29. processor like ProKey, you'll have to hold down both Alt and Shift
  30. while you press the keys on the numeric keypad.
  31.  
  32.      The characters available depend on the editing technique you use
  33. to create batch files.  DOS's COPY and EDLIN provide access to ASCII
  34. codes 128 through 254.  IBM's Professional Editor makes available ASCII
  35. codes 1 through 6, 11, 12, 14 through 31 and 127 through 254.  WordStar
  36. does not offer access to any of the codes.
  37.  
  38.      Several strategies can simplify menu construction.  Initial layout
  39. can be done with Professional Editor to take advantage of its what-you-
  40. see-is-what-you-get-display and its rapid search-and-replace function
  41. capability.  When you're relying on such an editor, using the Alt key
  42. to enter a long series of extended ASCII codes can be tedious.  A long
  43. double line might require you to press and hold the Alt key, type 205,
  44. and release the Alt key 30 times.  A better technique would to type 30
  45. asterisks and then replace them with character 205 via the editor's
  46. global search and replace.
  47.  
  48.      Professional Editor cannot, however, perform one necessary task.
  49. Many menus tend to be so large that you'll want to do what you can to
  50. avoid wasted lines on the screen.  A DOS quirk causes many batch files
  51. to end with a double prompt, forcing the top line of the menu off the
  52. screen.  This anomaly can be prevented by making a Ctrl-Z the last
  53. character of the last line of the ASCII file.  Professional Editor
  54. cannot perform this operation, but EDLIN can.  The final step in
  55. creating a menu with Professional Editor, then, is to bring it into
  56. EDLIN to add the terminating Ctrl-Z.  Once the menu is saved as a
  57. text file, you can write it to the screen at any time using the DOS
  58. TYPE command.  If you call your menu MENU.DSP, for example, you can
  59. display it by including the commands CLS and TYPE MENU.DSP in a batch
  60. file.
  61.  
  62.      Suppose you have added your own function key assignments for F1
  63. and F7 through F10 to the DOS default assignments for F2 through F6.
  64. F2 through F4 allow you to redisplay different segments of a previous
  65. command line.  F2 plus a character redisplays all characters of the
  66. previous command up to the first occurrence of the character you typed.
  67. You can also display all remaining characters (F3), skip all characters
  68. up to a given character (F4), and enter the currently display command
  69. line without executing the command to edit it further (F5).  The final
  70. DOS default (F6) types an end-of-file character, or Ctrl-Z, which is
  71. displayed as ^Z.  We will assume that you have added the following
  72. assignments to the remaining functin keys:  F1 is COPY, F7 is BASICA,
  73. F8 is the main menu display, F9 is A:, and F10 is B:.
  74.  
  75.      You can create a small ASCII display to remind yourself of these
  76. assignments.  This requires nothing more than EDLIN.  The first step
  77. is to invoke the editor with a new file name, such as EDLIN FK.ASC.
  78. You can begin immediately by sending EDLIN the command 1I to insert
  79. text starting at the first line.  You then type the ASCII code for a
  80. double-line upper left corner (Alt-201), followed by 37 asterisks, the
  81. ASCII code for a double-line upper right corner (Alt-187) and Enter.
  82.  
  83.      You begin the next line with the double-line border (Alt-186),
  84. then the text (F1 COPY), 15 spaces, the text (F2 Type to char), the
  85. double-line border (Alt-186), and Enter.  Enter the remaining lines
  86. containing text in the same way.  The final line includes a bottom left
  87. double-line corner (Alt-200), 37 asterisks, and a bottom right double-
  88. line corner (Alt-188).  After entering the last line, press Ctrl-Break
  89. to exit EDLIN's insert mode.
  90.  
  91.      The only task remaining before saving the display to a disk file
  92. is to change all the asterisks to the horizontal double-line character
  93. to finish the framing display.  This is easily accomplished with the
  94. EDLIN command 1,8R* Ctrl-Z Alt-205.  Typing E (Enter) saves the display
  95. and it is ready to use.
  96.  
  97.      Any time you wish to display the function key reminder on screen,
  98. just issue the command TYPE FK.ASC.  You might, for example, include
  99. the command as the last line of any batch file that returns to DOS
  100. after running an application program.  It could also be included as
  101. the last line in your AUTOEXEC.BAT file.
  102.  
  103.      DOS 2.0's PROMPT command provides additional screen control.  Its
  104. simplest use involves changing a prompt.  You can invoke it with the
  105. syntax PROMPT [prompt-text] from either the keyboard or a batch file.
  106. Prompt-text can consist of any of 13 arguments plus any text you want
  107. to insert into the prompt.  Each argument must begin with a dollar
  108. sign.  You can include the date ($d), time ($t), default ($n), path
  109. ($p), greater-than symbol ($g), less-than symbol ($l), DOS version
  110. number ($v), vertical bar ($b), double horizontal line ($q), dollar
  111. sign ($$), a carriage return/line feed sequence ($_), a backspace and
  112. erase ($h), and an Escape character ($e).
  113.  
  114.      Anything on the command line other than these arguments will be
  115. printed as part of the prompt.  The command PROMPT $n$g (or just
  116. PROMPT), typed from the keyboard or included in a batch file, will
  117. produce the normal DOS prompt.  But if you use the command PROMPT
  118. $d $n$g, the date will be included in the prompt, and it will appear,
  119. for example, as "Thu 8-14-85 A>".
  120.  
  121.      A more useful application would have the prompt report the current
  122. path (including the drive specifier) after you issue the command PROMPT
  123. $p$g.  If you are in the \EDISK directory of drive C:, for example,
  124. this command will produce the prompt "C:\EDISK".  You can include any
  125. text in the prompt command.  The command "PROMPT Charlie's DOS, Current
  126. Directory: $p$g" would produce the prompt "Charlie's DOS, Current
  127. Directory: C:\EDISK>".
  128.  
  129.      Although controlling the prompt is useful, the PROMPT command's
  130. most important function may well be providing a gateway to an extremely
  131. powerful display driver called ANSI.SYS.  ANSI.SYS lets you manipulate
  132. display functions precisely.  You can control cursor position (in a
  133. fashion similar to using BASIC's LOCATE, PRINT and CLS commands) and
  134. foreground and background colors and inverse video (similar to using
  135. BASIC's COLOR and SCREEN commands).  ANSI.SYS also reports on current
  136. cursor location (like BASIC's CSRLIN and POS commands) and offers
  137. several functions not available in BASIC.  (ANSI.SYS also enables you
  138. to redefine keys, although this capability is negligible compared to
  139. that of such macro processors as ProKey, SuperKey, and Keyworks).
  140.  
  141.      In order for DOS to install the ANSI.SYS driver, the ANSI.SYS
  142. file must be on your system start-up dis.  The system start-up disk
  143. must contain a file called CONFIG.SYS, and this file must contain the
  144. line DEVICE=ANSI.SYS.
  145.  
  146.      Each call to an ANSI.SYS function begins with an Escape code.
  147. Since PROMPT allows you to send an Escape code to DOS ($e), this
  148. command provides access to the ANSI.SYS commands.  The syntax of
  149. ANSI.SYS (modified to make use of the PROMPT command) and its functions
  150. are shown in Table 1 below.  The visual effects of various Set Graphics
  151. Rendition (SGR) function parameters are listed in Table 2.
  152.  
  153.      When you combine the power of the ANSI.SYS display driver with
  154. the PROMPT command, you can turn your system prompt into a useful
  155. display.  The batch file PROMPT1.BAT shown below was created with
  156. EDLIN.  It produces an informative display such that whenever you are
  157. in DOS, this prompt lets you see both the date and the path to the
  158. current directory.  The prompt also shows the date the system was last
  159. revised and an indication that the system is waiting for a command.
  160.  
  161.      The first parameter specified in the PROMPT command ($e[s) saves
  162. the cursor position when a DOS command is invoked.  The next parameter
  163. ($e[1;1H) moves the cursor to row 1, column 1, ensuring that the
  164. current date, the path and the date the system was last revised will
  165. appear at the top of the screen, regardless of where the cursor was
  166. when the command was initiated.  The next cursor movement parameters
  167. ($e[1;33H and $e[1;67H) locate the path and revision information
  168. properly on row 1.  The last cursor movement parameter ($e[u), which
  169. appears toward the end of the PROMPT command, returns the cursor to
  170. the position it was in before the DOS command was issued, at which
  171. point the system can begin writing the command prompt.
  172.  
  173.      Controlling the cursor with this scheme produces intriguing and
  174. useful results.  If the DOS command does not generate screen output,
  175. the date/path/revision line will appear immediately above the command
  176. prompt.  But any screen output will appear between the date/path/
  177. revision line and the command prompt.  This display scheme helps focus
  178. the user's attention appropriately during day-to-day activities with
  179. DOS.
  180.  
  181.      The prompt also contains several ANSI.SYS commands that control
  182. video attributes to guide the eye efficiently to the desired
  183. information.  The parameter $e[36m makes the date appear in cyan.
  184. (This command has no effect on an IBM Monochrome Display.)  The next
  185. parameter ($e[K) erases to the end of row 1.  Inverse video is then
  186. turned on ($e[7m) for the path information, making it the most salient
  187. information in the display.  The character attributes are returned to
  188. normal status for the revision information ($e[0m), and high-intensity
  189. is turned on for the command prompt ($e[1m).  Finally, character
  190. attributes are returned to normal status ($e[0m) at the end of the
  191. prompt.
  192.  
  193.      PROMPT1.BAT illustrates several characteristics of the PROMPT/
  194. ANSI.SYS system.  You can string together any number of parameters on
  195. the same command line to produce any desired effect.  Your only
  196. limitation is the 127-character maximum length of the DOS command
  197. line.  Cursor movement commands may be interspersed with video
  198. attribute commands to create eye-catching displays.  Finally, the
  199. extended ASCII set is available.  For example, you can combine the
  200. double horizontal line (ASCII 205) with a right arrowhead (ASCII 16)
  201. to produce a "pointer."
  202.  
  203.      The PROMPT/ANSI.SYS system also enables you to control foreground
  204. and background colors in DOS.  This feat is easy in BASIC, but any
  205. changes made in BASIC are removed when you return to DOS.  Prior to
  206. DOS 2.0, control of colors in DOS required programming in assembly
  207. language.  Now the conditional logic available in batch files and the
  208. display control provided by ANSI.SYS and PROMPT have eliminated this
  209. problem.
  210.  
  211.      SCREEN1.BAT gives you control over foreground and background
  212. colors while in DOS.  You invoke the batch file with the syntax SCREEN
  213. foreground background.  To produce white text on a blue screen, for
  214. example, you would type SCREEN WHILE BLUE.  (Note that SCREEN1.BAT,
  215. and any program to control DOS screen colors, will not be effective
  216. if the DOS prompt contains color commands.)
  217.  
  218.      WHITE would be the value assigned to "%1" in SCREEN1.BAT, and the
  219. batch file would test this variable until it found a match on the line
  220. "IF WHITE==%1 GOTO FWHITE".  The conditional logic would send control
  221. to the label ":FWHITE", which would set the foreground color.  (Note
  222. that the test must be performed for both uppercase and lowercase
  223. strings.  DOS is normally insensitive to case, but the batch file
  224. conditional that tests for matching strings is case-sensitive.  You
  225. are searching for an exact match with a string, and uppercase and
  226. lowercase representations of the same word are legitimately different
  227. string values.)
  228.  
  229.      After setting the foreground color, an unconditional branch (GOTO
  230. BACK) sends control to the routine that sets the background color.  A
  231. new test is performed on "%2", which would find a match at the line
  232. "IF BLUE==%2 GOTO BBLUE".  ":BBLUE" would then set the background color
  233. and send control to the exit routine ":END".  THe two "ECHO ON,ECHO
  234. OFF,CLS" sequences in this batch file are necessary to force each
  235. PROMPT/ANSI color change when "ECHO" is off.
  236.  
  237.      Notice the "ECHO Wait ..." lines that appear twice in this batch
  238. file.  These are not trivial or cosmetic additions to the program.  At
  239. its worst, this batch file takes about 15 seconds to complete.  In such
  240. a situation, providing an indication that something is actually going
  241. on is a sound idea.  Otherwise, someone using the batch file for the
  242. first time is likely to terminate it prematurely on the assumption that
  243. it's not working.  Many operations have been brought to a grinding halt
  244. by the failure to include simple messages such as "Wait ..."
  245.  
  246.      The sluggish execution of this batch file is troublesome.  If you
  247. think about the logic of the problem, you'll realize that you`re
  248. forcing the computer to do more work than necessary.  It is clear that
  249. you need a branching strategy, but requiring as many as 31 IF string
  250. comparisons is probably not the best way to proceed.  All you really
  251. need to do is go directly to the appropriate foreground routine, then
  252. to the appropriate background routine.
  253.  
  254.     SCREEN2.BAT is a more efficient and elegant version of SCREEN1.BAT.
  255. It replaces the conditional IF logic with unconditional GOTO logic,
  256. eliminating the need for all but two of the tests of string values.
  257. Not only is this batch file both shorter and more emotionally
  258. satisfying than its precursor, it runs with a worst-case time of six
  259. seconds -- an improvement of 9 seconds over its more cumbersome
  260. predecessor.  Rethinking your logic after completing a program can
  261. frequently produce this kind of time savings, reaffirming the adage
  262. that no program is ever a total loss ...it can always be used as a
  263. bad example.
  264. - - - - -
  265.  
  266. Table 1: Selected ANSI.SYS/PROMPT functions
  267.  
  268. DOS manual    Modified
  269.  mnemonic      syntax          Purpose
  270.  
  271.   CUP      PROMPT $e[#;#H     Moves cursor to row #, column #
  272.   CUU      PROMPT $e[#A       Moves cursor up # rows without changing
  273.                                 column
  274.   CUD      PROMPT $e[#B       Moves cursor down # rows without changing
  275.                                 column
  276.   CUF      PROMPT $e[#C       Moves cursor right # columns without
  277.                                 changing row
  278.   CUB      PROMPT $e[#D       Moves cursor left # columns without
  279.                                 changing row
  280.   SCP      PROMPT $e[s        Saves current cursor position so that it
  281.                                 can be restored with RCP
  282.   RCP      PROMPT $e[u        Returns cursor to position saved with SCP
  283.   ED       PROMPT $e[2J       Clears screen and homes cursor
  284.   EL       PROMPT $e[k        Erases from current cursor position to
  285.                                 end of line
  286.   SGR      PROMPT $e[#;...;#m   Sets character attributes for color,
  287.                                 bold, underscore, blinking and inverse
  288.                                 video (see Table 2 for values of #)
  289.  
  290. - - - - -
  291. Table 2: Set Graphics Rendition (SGR) function parameters
  292.  
  293. Effect               Command          Notes
  294. Attributes
  295.   Normal             PROMPT $e[0m     All attributes are off; w on b
  296.   High intensity     PROMPT $e[1m
  297.   Underscore         PROMPT $e[4m     IBM monochrome only
  298.   Blinking           PROMPT $e[5m
  299.   Inverse video      PROMPT $e[7m
  300.   Invisible          PROMPT $e[8m
  301.  
  302. Foreground Color
  303.   Black              PROMPT $e[30m    Gray in high intensity
  304.   Blue               PROMPT $e[34m
  305.   Green              PROMPT $e[32m
  306.   Cyan               PROMPT $e[36m
  307.   Red                PROMPT $e[31m
  308.   Magenta            PROMPT $e[35m
  309.   Brown              PROMPT $e[33m    Yellow in high intensity
  310.   White              PROMPT $e[37m
  311.  
  312. Background Color
  313.   Black              PROMPT $e[40m
  314.   Blue               PROMPT $e[44m
  315.   Green              PROMPT $e[42m
  316.   Cyan               PROMPT $e[46m
  317.   Red                PROMPT $e[41m
  318.   Magenta            PROMPT $e[45m
  319.   Brown              PROMPT $e[43m
  320.   White              PROMPT $e[47m
  321. - - - - -
  322. PROMPT1.BAT: Produces screen output showing current date, path,
  323.              revision date and a "COMMAND=>" prompt.
  324.  
  325. ECHO OFF
  326. PROMPT $e[s $e[1;1H$e[36mDate=>$d $e[K$e[7m$e[1;34HPath=>$p
  327.    $e[1;67H$e[0mRev. 01/01/85$e[u$e[1mCOMMAND+>$e[0m
  328.  
  329. - - - - -
  330. SCREEN1.BAT:  To manipulate foreground and background colors in DOS
  331.  
  332. ECHO OFF
  333. CLS
  334. ECHO Wait ...
  335. IF ZIP==%1ZIP GOTO BACK
  336. IF BLACK==%1 GOTO FBLACK
  337. IF black==%1 GOTO FBLACK
  338. IF RED==%1 GOTO FRED
  339. IF red==%1 GOTO FRED
  340. IF GREEN==%1 GOTO FGREEN
  341. IF green==%1 GOTO FGREEN
  342. IF BROWN==%1 GOTO FBROWN
  343. IF brown==%1 GOTO FBROWN
  344. IF BLUE==%1 GOTO FBLUE
  345. IF blue==%1 GOTO FBLUE
  346. IF MAGENTA==%1 GOTO FMAGENTA
  347. IF magenta==%1 GOTO FMAGENTA
  348. IF CYAN==%1 GOTO FCYAN
  349. IF cyan==%1 GOTO FCYAN
  350. IF WHITE==%1 GOTO FWHITE
  351. IF white==%1 GOTO FWHITE
  352. :FBLACK
  353. PROMPT $e[30m
  354. GOTO BACK
  355. :FRED
  356. PROMPT $e[31m
  357. GOTO BACK
  358. :FGREEN
  359. PROMPT $e[32m
  360. GOTO BACK
  361. :FBROWN
  362. PROMPT $e[33m
  363. GOTO BACK
  364. :FBLUE
  365. PROMPT $e[34m
  366. GOTO BACK
  367. :FMAGENTA
  368. PROMPT $e[35m
  369. GOTO BACK
  370. :FCYAN
  371. PROMPT $e[36m
  372. GOTO BACK
  373. :FWHITE
  374. PROMPT $e[37m
  375. GOTO BACK
  376. :BACK
  377. ECHO ON
  378. ECHO OFF
  379. CLS
  380. ECHO Wait ...
  381. IF ZIP==%2ZIP GOTO END
  382. IF BLACK==%2 GOTO BBLACK
  383. IF black==%2 GOTO BBLACK
  384. IF RED==%2 GOTO BRED
  385. IF red==%2 GOTO BRED
  386. IF GREEN==%2 GOTO BGREEN
  387. IF green==%2 GOTO BGREEN
  388. IF BROWN==%2 GOTO BBROWN
  389. IF brown==%2 GOTO BBROWN
  390. IF BLUE==%2 GOTO BBLUE
  391. IF blue==%2 GOTO BBLUE
  392. IF MAGENTA==%2 GOTO BMAGENTA
  393. IF magenta==%2 GOTO BMAGENTA
  394. IF CYAN==%2 GOTO BCYAN
  395. IF cyan==%2 GOTO BCYAN
  396. IF WHITE==%2 GOTO BWHITE
  397. IF white==%2 GOTO BWHITE
  398. :BBLACK
  399. PROMPT $n$g$e[40m
  400. GOTO END
  401. :BRED
  402. PROMPT $n$g$e[41m
  403. GOTO END
  404. :BGREEN
  405. PROMPT $n$g$e[42m
  406. GOTO END
  407. :BBROWN
  408. PROMPT $n$g$e[43m
  409. GOTO END
  410. :BBLUE
  411. PROMPT $n$g$e[44m
  412. GOTO END
  413. :BMAGENTA
  414. PROMPT $n$g$e[45m
  415. GOTO END
  416. :BCYAN
  417. PROMPT $n$g$e[46m
  418. GOTO END
  419. :BWHITE
  420. PROMPT $n$g$e[47m
  421. :END
  422. ECHO ON
  423. ECHO OFF
  424. CLS
  425.  
  426. - - - - -
  427. SCREEN2.BAT: An improved version of SCREEN1.BAT
  428.  
  429. ECHO OFF
  430. CLS
  431. ECHO Wait ...
  432. IF ZIP==%1ZIP GOTO BACK
  433. GOTO F%1
  434. :FBLACK
  435. PROMPT $e[30m
  436. GOTO BACK
  437. :FRED
  438. PROMPT $E[31m
  439. GOTO BACK
  440. :FGREEN
  441. PROMPT $e[32m
  442. GOTO BACK
  443. :FBROWN
  444. PROMPT $e[33m
  445. GOTO BACK
  446. :FBLUE
  447. PROMPT $e[34m
  448. GOTO BACK
  449. :FMAGENTA
  450. PROMPT $e[35m
  451. GOTO BACK
  452. :FCYAN
  453. PROMPT $e[36m
  454. GOTO BACK
  455. :FWHITE
  456. PROMPT $e[37m
  457. GOTO BACK
  458. :BACK
  459. ECHO ON
  460. ECHO OFF
  461. CLS
  462. ECHO Wait ...
  463. IF ZIP==%2GOTO END
  464. GOTO B%2
  465. :BBLACK
  466. PROMPT $n$g$e[40m
  467. GOTO END
  468. :BRED
  469. PROMPT $n$g$e[41m
  470. GOTO END
  471. :BGREEN
  472. PROMPT $n$g$e[42m
  473. GOTO END
  474. :BBROWN
  475. PROMPT $n$g$e[43m
  476. GOTO END
  477. :BBLUE
  478. PROMPT $n$g$e[44m
  479. GOTO END
  480. :BMAGENTA
  481. PROMPT $n$g$e[45m
  482. GOTO END
  483. :BCYAN
  484. PROMPT $n$g$e[46m
  485. GOTO END
  486. :BWHITE
  487. PROMPT $n$g$e[47m
  488. :END
  489. ECHO ON
  490. ECHO OFF
  491. CLS
  492.  
  493.